/*
	Visp is an opensource visual performance application built with Adobe® AIR™.
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
	
	Mike Creighton can be found at http://www.mikecreighton.com	
*/
package com.visp.transitions
{
	import com.visp.constants.OutputSize;
	import com.visp.events.TransitionEvent;
	import com.visp.render.Layer;
	
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.getTimer;
	
	[Event(name="transitionExpired", type="com.visp.events.TransitionEvent")]
	[Event(name="transitionStart", type="com.visp.events.TransitionEvent")]

	public class AbstractTransition extends EventDispatcher implements ITransition
	{
		protected static const _COPY_RECT : Rectangle = new Rectangle(0, 0, OutputSize.WIDTH, OutputSize.HEIGHT);
		protected var _output : BitmapData;
		protected var _startTime : Number;
		
		public function AbstractTransition(target:IEventDispatcher=null)
		{
			super(target);
			this._output = new BitmapData(OutputSize.WIDTH, OutputSize.HEIGHT, true, 0x00000000);
		}
		
		public function start(queued : BitmapData, active : BitmapData) : void {
			this._startTime = getTimer();
			this.dispatchEvent(new TransitionEvent(TransitionEvent.START));
		}
		
		public function render(queued : BitmapData, active : BitmapData) : BitmapData
		{
			if(getTimer() - this._startTime >= TransitionManager.getInstance().getDuration()){
				this.dispatchEvent(new TransitionEvent(TransitionEvent.EXPIRED));
			}
			return this._output;
		}
		
		public function destroy() : void 
		{
			this._output.dispose();
			this._output = null;
		}
	}
}